<template>
  <div class="containers">
    <div class="title">请填写你要找回密码的美团账号</div>
    <input v-model="phone" placeholder="手机号" type="number">
    <div @click="phone.length && stepTwo()" :class="{disabled: !phone.length}" class="next">下一步</div>
  </div>
</template>

<script>
import { mapActions } from 'vuex'
export default {
  name: 'SurePhone',
  data() {
    return {
      phone: ''
    }
  },
  mounted() {
    this.$store.dispatch('saveStep', 'stepOne')
  },
  methods: {
    ...mapActions(['saveStep']),
    /** 提示 */
    messageTips(type, msg) {
      this.$Message[type]({
        background: true,
        content: msg
      })
    },
    /** 点击下一步 进入第二步 */
    async stepTwo() {
      let reg = /^(?:(?:\+|00)86)?1(?:(?:3[\d])|(?:4[5-7|9])|(?:5[0-3|5-9])|(?:6[5-7])|(?:7[0-8])|(?:8[\d])|(?:9[1|8|9]))\d{8}$/
      if (this.phone) {
        if(reg.test(this.phone)) {
          let res = await this.$api.findPass({ phone: this.phone })
          if (res.code === 0) {
            this.saveStep('stepTwo')
            this.$router.push('/findPassword/slideUnlock')
            this.$store.dispatch('changePassUsePhone', res.phone)
          } else {
            this.messageTips('error', '查询失败,没有此账号,请先注册')
          }
        }
        else {
          this.messageTips('error', '请输入正确的手机号')
        }
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.containers {
  width: 300px;
  margin: 0 auto;
  .title {
    font-size: 16px;
    color: #333;
    margin-bottom: 50px;
  }
  input {
    font-size: 16px;
    border: none;
    border-bottom: 1px solid #d8d8d8;
    width: 300px;
    box-sizing: border-box;
    margin-bottom: 30px;
    background-color: #fff
  }
  .next {
    font-size: 16px;
    background: linear-gradient(135deg,#FFD000 0,#FFBD00 100%);
    border-radius: 8px;
    border: 1px solid #FFD000;
    text-align: center;
    color: #222222;
    height: 36px;
    line-height: 36px;
    cursor: pointer;
    width: 300px;
    display: inline-block;
  }
  .disabled {
    background-image: linear-gradient(135deg,#FFF5CA 0,#FFF2CC 100%);
    color: rgba(34,34,34,.5);
    cursor: not-allowed;
    border: none;
  }
}
</style>